import sys
sys.path.append('../../lib')

from chromadb import Documents, EmbeddingFunction, Embeddings
from casevo import LLM_INTERFACE

from openai import OpenAI

BASE_URL = 'https://api.uniapi.io/v1'
API_KEY = ''

# Model Name
CHAT_MODEL = 'gpt-5-mini'
EMBEDDING_MODEL = 'text-embedding-3-small'





class MyEmbedding(EmbeddingFunction):
    def __init__(self,llm, tar_len):
        #super.__init__()
        #   文章数量
        self.SEND_LEN = tar_len
        
        # 大模型接口
        self.llm = llm
    
    def __call__(self, input: Documents) -> Embeddings:
        # embed the documents somehow
        res_list = []
        cur_list = []
        for item in input:
            cur_list.append(item)
            if len(cur_list) >= self.SEND_LEN:
                res = self.llm.send_embedding(cur_list)
                res_list.extend(res)
                cur_list = []
        if len(cur_list) > 0:
            res = self.llm.send_embedding(cur_list)
            res_list.extend(res)

        return res_list


class OpenaiLLM(LLM_INTERFACE):
    def __init__(self, tar_len):
        
        self.embedding_len = tar_len
        self.embedding_function = MyEmbedding(self, self.embedding_len)
       
    
    def send_message(self, prompt, json_flag=False):
        pass
        

    def send_embedding(self, text_list):
        pass

        
    def get_lang_embedding(self):
        
        return self.embedding_function